#include<iostream>
#include<cassert>
#include<unistd.h>
#include<pthread.h>

using namespace std;

pthread_t minTID;
//新线程
void* routine(void* args)
{
    sleep(1);
    char* msg = static_cast<char*>(args);
     while(true)
    {
        printf("%s: 我是新线程，我的 pid：%d, ppid:%d, tid:0X%0x\n",msg,getpid(),getppid(),pthread_self());
        sleep(1);
        pthread_cancel(minTID);
    }
}

int main()
{
    pthread_t tid[5];
    minTID = pthread_self();
    for(int i=0 ;i<5;++i)
    {
        char* buff = new char[64];

        snprintf(buff,sizeof(buff),"thread%d",i+1);  
        int n = pthread_create(tid+i,nullptr,routine,buff);
        assert(0==n);
        (void)n;
    }

    void* ret;
    for(int i =0;i<5;++i)
    {
        pthread_join(tid[i],&ret);
        printf("线程%d ：exit_code: %d\n",i,(long long)ret);
    }
    return 0;
}